import React, { Component } from "react";
import { Link, Route, Switch } from "react-router-dom";

class Home extends Component {
  render() {
    return <div>这是home组件</div>;
  }
}

class About extends Component {
  render() {
    return <div>这是About组件</div>;
  }
}

class Mine extends Component {
  render() {
    return <div>这是Mine组件</div>;
  }
}

class NoMatch extends Component {
  render() {
    return <div>404 not found</div>;
  }
}

class App extends Component {
  render() {
    return (
      <>
        <h2>react-router-404</h2>
        <ul>
          <li>
            <Link to="/home">首页</Link>
          </li>
          <li>
            <Link to="/about">关于页</Link>
          </li>
          <li>
            <Link to="/mine">我的页</Link>
          </li>
        </ul>

        <hr />

        <Switch>
          {/* 404的时候，不能去掉Switch */}
          {/* 404要写在所有Route的最后 */}
          <Route path="/home" component={Home}></Route>
          <Route path="/about" component={About}></Route>
          <Route path="/mine" component={Mine}></Route>
          <Route path="*" component={NoMatch}></Route>
        </Switch>
      </>
    );
  }
}

export default App;
